package xm.control.bar.barContent
{
	import flash.display.DisplayObject;
	
	import xm.control.bar.ActionBar;
	import xm.control.bar.base.BarBase;
	import xm.control.bar.base.ContentBase;
	import xm.definition.Align;
	
	/**
	 * <br> 클래스 설명 : </br>
	 * @author 김정환
	 */	
	public class TitleContent extends ContentBase
	{
		
		//-----------------------------------------------------------------------------------
		// public vars
		//-----------------------------------------------------------------------------------
		/**
		 * 기본값 : Align.CENTER = "center";  
		 */		
		public var align : String = "center";
		
		
		//-----------------------------------------------------------------------------------
		// protected / internal vars
		//-----------------------------------------------------------------------------------
		
		
		
		
		//-----------------------------------------------------------------------------------
		// private vars
		//-----------------------------------------------------------------------------------
		
		
		
		
		//-----------------------------------------------------------------------------------
		// public functions
		//-----------------------------------------------------------------------------------
		
		/**
		 * constructor 
		 */	
		public function TitleContent()
		{
			super();
		}
		
		
		/**
		 * @param s
		 * @param rect
		 */		
		override public function apply( container:BarBase ):void
		{
			super.apply( container );
			
			var i : int,
			len : int,
			content : DisplayObject,
			sum : Number,
			extraWidth : Number;
			
			i=0;
			len = contentList.length;
			sum = 0;
			
			while( i<len )
			{
				content = contentList[ i ] as DisplayObject;
				if( content != null )
				{
					content.x = sum;
					content.y = Math.round( ( container.height - content.height ) / 2 + paddingTop );
					
					sum += content.width + gapBetweenContents;
				}
				++i;
			}
			
			
			// 맨 마지막 컨텐츠 오른쪽 갭은 다시 제거해주고, 
			sum -= gapBetweenContents;
			
			switch( align )
			{
				case Align.CENTER :
					extraWidth = Math.round( ( container.viewWidth - sum ) / 2 );
					break;
				
				case Align.LEFT :
					extraWidth = ( ( container as ActionBar ).isNavigationContent ) ? ( container as ActionBar ).navigationContentWidth+paddingLeft : paddingLeft; 
					break;
				
				case Align.RIGHT :
					extraWidth = ( ( container as ActionBar ).isActionContent ) ?  Math.round( container.viewWidth - sum - paddingRight ) - ( container as ActionBar ).actionContentWidth: Math.round( container.viewWidth - sum - paddingRight );
					break;
			}
			
			i=0;
			while( i<len )
			{
				content = contentList[ i ] as DisplayObject;
				if( content != null )
				{
					content.x += extraWidth;
				}
				
				++i;
			}
		}
		
		//-----------------------------------------------------------------------------------
		// life cycle functions
		//-----------------------------------------------------------------------------------
		
		/**
		 * 변수, 객체 생성됨.
		 */		
		override public function createChildren():void
		{
			super.createChildren();
		}
		
		/**
		 * 생성완료시점.
		 */		
		override public function creationComplete():void
		{
			super.createChildren();
		}
		
		/**
		 * 화면에 add됨.
		 */		
		override public function add():void
		{
			super.add();
		}
		
		/**
		 * 화면에서 remove됨. 
		 */		
		override public function remove():void
		{
			super.remove();
		}
		
		/**
		 * 메모리에서 destory됨. 
		 */		
		override public function destroy():void
		{
			
			align = null;
			
			super.destroy();
		}
		
		//-----------------------------------------------------------------------------------
		// setter / getter
		//-----------------------------------------------------------------------------------
		
		
		
		//-----------------------------------------------------------------------------------
		// protected functions
		//-----------------------------------------------------------------------------------
		
		
		
		//-----------------------------------------------------------------------------------
		// internal functions
		//-----------------------------------------------------------------------------------
		
		
		
		
		//-----------------------------------------------------------------------------------
		// private functions
		//-----------------------------------------------------------------------------------
		
		
		
		//-----------------------------------------------------------------------------------
		// event handler
		//-----------------------------------------------------------------------------------
		
		
		
		
		
		
		
		
		
	}
}